//
//  GSRootTabBarController.m
//  GameSky
//
//  Created by lanou on 16/1/10.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSRootTabBarController.h"
#import "GSNewsViewController.h"
#import "GSStrategyViewController.h"
#import "GSSubscribeViewController.h"
#import "GSMainViewController.h"
#import "XSportLight.h"

@interface GSRootTabBarController () <GSMainViewControllerDelegate,XSportLightDelegate>

@end

@implementation GSRootTabBarController

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    // 夜间模式
    self.tabBar.dk_barTintColorPicker = DKColorWithRGB(0xffffff, 0x343434);
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *result = [defaults objectForKey:@"XSportLight"];
    
    // 如果是第一次使用,就进入新手引导流程;
    if (![result isEqualToString:@"YES"]){
        // 1.创建聚光灯引导;
        XSportLight *SportLight = [[XSportLight alloc]init];
        SportLight.messageArray = @[@"这是《游民星空》",
                                    @"点这里查看新闻",
                                    @"点这里查看攻略",
                                    @"点这里查看订阅",
                                    @"频道管理",
                                    @"这儿是登陆及设置按钮",
                                    @"欢迎使用#^_^#"];
        SportLight.rectArray = @[[NSValue valueWithCGRect:CGRectMake(0,0,0,0)],
                                 [NSValue valueWithCGRect:CGRectMake(60, kScreenHeight - 20, 50, 50)],
                                 [NSValue valueWithCGRect:CGRectMake(kScreenWidth/2, kScreenHeight - 20, 50, 50)],
                                 [NSValue valueWithCGRect:CGRectMake(kScreenWidth - 60, kScreenHeight - 20, 50, 50)],
                                 [NSValue valueWithCGRect:CGRectMake(kScreenWidth - 20, 42, 50, 50)],
                                 [NSValue valueWithCGRect:CGRectMake(25,45,50,50)],
                                 [NSValue valueWithCGRect:CGRectMake(0,0,0,0)]];
        // 2.设置引导代理;
        SportLight.delegate = self;
        // 3.添加模态视图;
        [self presentViewController:SportLight animated:NO completion:^{
            [defaults setObject:@"YES" forKey:@"XSportLight"];
            [defaults synchronize];
        }];
    }
}

- (void)XSportLightClicked:(NSInteger)index
{
    NSLog(@"%ld",(long)index);
}


- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupChildViewController:[GSNewsViewController class] title:@"新闻" imageName:@"common_Button_XinWen_UIMode_Day" selectedImageName:@"common_Button_XinWen_Selected_UIMode_Day"];
    [self setupChildViewController:[GSStrategyViewController class] title:@"攻略" imageName:@"common_Button_GongLue_UIMode_Day" selectedImageName:@"common_Button_GongLue_Selected_UIMode_Day"];
    [self setupChildViewController:[GSSubscribeViewController class] title:@"订阅" imageName:@"common_Button_DingYue_UIMode_Day" selectedImageName:@"common_Button_DingYue_Selected_UIMode_Day"];
    
    // 默认显示新闻界面;
    self.selectedIndex = 0;
}

// 添加子控制器方法;
- (void)setupChildViewController:(Class)class title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName {
    // 1.添加一个导航控制器;
    UINavigationController *naviC = [[UINavigationController alloc] initWithRootViewController:[[class alloc] init]];
    [self addChildViewController:naviC];
    // 2.设置导航控制器属性;
    naviC.tabBarController.tabBar.itemPositioning = UITabBarItemPositioningFill;
    naviC.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    naviC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    // 3.设置导航控制器的根控制器;
    GSMainViewController *mainVC = (GSMainViewController *)naviC.viewControllers[0];
    // 4.设置抽屉代理;
    mainVC.delegate = self;
}

- (void)drawerControllerWillOpen:(ICSDrawerController *)drawerController
{
    self.view.userInteractionEnabled = NO;
}

- (void)drawerControllerDidClose:(ICSDrawerController *)drawerController
{
    self.view.userInteractionEnabled = YES;    
}

/**
 *  抽屉效果代理方法
 */
- (void)showListMenu:(BOOL)isSlected
{
    [self.drawer open];
}

@end
